#pragma once
#include "videoInput.h"
#include "ObjectRegion.h"

typedef struct  
{
	unsigned char point;
	unsigned char min;
	unsigned char max;
}SingleColorRange;

typedef struct  
{
	SingleColorRange color1;
	SingleColorRange color2;
	SingleColorRange color3;
}ObjectColorRange;

class ObjectColorLUT
{
public:
	unsigned char color1[256];
	unsigned char color2[256];
	unsigned char color3[256];

	ObjectColorLUT()
	{
		for ( int i=0 ;i<256 ;i++)
		{
			this->color1[i] = 0;
			this->color2[i] = 0;
			this->color3[i] = 0;
		}
	}
};

class HuroCupVision
{
public:
	ObjectColorRange hsvObjRange[8];
	ObjectColorLUT hsvObjLUT;

	videoInput *VI;
	int camID;
	int camWidth,camHeight;
	IplImage* camFrame;	//RGB frame

	//rectify and mapping
	IplImage* camFrame_HSV;	//HSV frame

	//object image
	unsigned char eventIndex,objectIndex,colorIndex;
	cv::Mat isPixelSearched;

	HuroCupVision(void);
	void initial();
	void run(unsigned short objIndex);
	bool findBall();
	bool findGoal();
	bool findClosestObstacle( unsigned char objIndex ,int minPixelNumbers ,bool isMulti );
	bool findObstacle();
	bool findLine();
	bool findObject(unsigned char objIndex);	//1 parameter
	bool findObject(unsigned char objIndex ,int minPixelNumbers);	//2 parameters
	bool findObject(unsigned char objIndex ,int minPixelNumbers ,bool isMulti);		//3 parameters
	bool findObject(unsigned char objIndex ,int minPixelNumbers ,RegionOfInterest ROI ,bool isMulti);	//4 parameters
	void searchAround(int i ,int j ,unsigned short colorIndex ,ObjectRegion *objRegion);

	void LineDetect(IplImage *HSV , IplImage *BGR);
	void thinningIteration(cv::Mat& im, int iter);
	void thinning(const cv::Mat& src, cv::Mat& dst);
	void doOpenClose(IplImage *temImg , int maskSize ,int iter , int choose);
	void HoughTransform(cv::Mat src);
};

